package com.gzxw.mogublog.web.controller;

import com.gzxw.mogublog.utils.JsonUtils;
import com.gzxw.mogublog.utils.ResultUtil;
import com.gzxw.mogublog.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @program: mogublog
 * @description: 第三方登录相关接口
 * @author: gzxw
 * @create: 2023-04-08 12:09
 **/

@RestController
@RequestMapping("/oauth")
@RefreshScope
public class AuthController {

    @Value(value = "${justAuth.clientId.gitee}")
    private String giteeClienId;

    @Value(value = "${justAuth.clientSecret.gitee}")
    private String giteeClientSecret;


    @Autowired
    private StringRedisTemplate stringRedisTemplate;




    // 获取用户
    @GetMapping("/verifyUser/{accessToken}")
    public String verifyUser(@PathVariable("accessToken") String accessToken) {

        String userInfo = stringRedisTemplate.opsForValue().get("USER_TOKEN" + ":" + accessToken);
        if (StringUtils.isEmpty(userInfo)) {
            return ResultUtil.result("error","token令牌未被识别");
        }else {
            Map<String, Object> map = JsonUtils.jsonToMap(userInfo);
            return ResultUtil.result("success",map);
        }
    }


    @GetMapping("/delete/{accessToken}")
    public String deleteUserAccessToken(@PathVariable("accessToken") String accessToken) {
        stringRedisTemplate.delete("USER_TOKEN"+":"+accessToken);
        return ResultUtil.result("success","删除成功");
    }



}
